<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .pink {
        background-color: pink;
      }
    </style>
  </head>
  <body>
    <button class="pink">张飞</button>
    <button>关羽</button>
    <button>鲁班</button>
    <button>诸葛亮</button>
    <button>曹操</button>
    <button>刘备</button>
    <script>
      let color = document.querySelectorAll("button");
      for (let i = 0; i < color.length; i++) {
        color[i].addEventListener("click", function () {
          let btn = document.querySelector(".pink")
          btn.classList.remove("pink")
          this.classList.add("pink")
        })
      }
    </script>
  </body>
</html>
